package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.MissionCenterItemAddDTO;
import org.jsola.hr.dto.MissionCenterItemUpdateDTO;
import org.jsola.hr.entity.MissionCenterItemDO;
import org.jsola.hr.query.MissionCenterItemQuery;
import org.jsola.hr.service.IMissionCenterItemService;
import org.jsola.hr.vo.MissionCenterItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 任务调度中心任务子项表
 *
 * @author zhr
 */
@Component
public class MissionCenterItemTestHelper extends BaseTestHelper {
    
    @Autowired
    private IMissionCenterItemService missionCenterItemService;

    /**
     * 生成add测试数据
     * @return MissionCenterItemAddDTO
     */
    public MissionCenterItemAddDTO getMissionCenterItemAddDTO(){
        MissionCenterItemAddDTO missionCenterItemAddDTO = new MissionCenterItemAddDTO();
        missionCenterItemAddDTO.setMissionCenterId(getRandomValue("varchar",32));
        missionCenterItemAddDTO.setState(SafeKit.getInteger(getRandomValue("int",1)));
        missionCenterItemAddDTO.setTableData(getRandomValue("text",2147483647));
        missionCenterItemAddDTO.setRemark(getRandomValue("varchar",255));
        missionCenterItemAddDTO.setFeedbackUser(getRandomValue("varchar",32));
        missionCenterItemAddDTO.setFeedbackDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        return missionCenterItemAddDTO;
    }


    /**
     * 生成update测试数据
     * @return MissionCenterItemUpdateDTO
     */
    public MissionCenterItemUpdateDTO getMissionCenterItemUpdateDTO(MissionCenterItemVO missionCenterItemVO){
        return missionCenterItemService.selectDOById(missionCenterItemVO.getId(), SITE_ID).to(MissionCenterItemUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return MissionCenterItemQuery
     */
    public MissionCenterItemQuery getMissionCenterItemQuery() {
        MissionCenterItemQuery missionCenterItemQuery = new MissionCenterItemQuery();
        List<MissionCenterItemDO> missionCenterItemDOList = missionCenterItemService.list(new MissionCenterItemDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(missionCenterItemDOList)) {
            MissionCenterItemDO missionCenterItemDO = missionCenterItemDOList.get(0);
            missionCenterItemQuery = missionCenterItemDO.to(MissionCenterItemQuery.class);
        }
        return missionCenterItemQuery;
    }

    /**
     * 保存示例
     * @return MissionCenterItemVO
     */
    public MissionCenterItemVO saveMissionCenterItemExample(){
        MissionCenterItemAddDTO addDTO = this.getMissionCenterItemAddDTO();
        MissionCenterItemVO missionCenterItemVO = missionCenterItemService.save(addDTO,buildTokenUser());
        return missionCenterItemVO;
    }


}

